comp_include _expand _get_cword


_gzip()
{
    local cur prev xspec IFS=$'\t\n'

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( compgen -W '-c -d -f \
            -h -l -L -n -N -q -r -S -t -v -V \
            -1 -2 -3 -4 -5 -6 -7 -8 -9 \
            --stdout --decompress --force --help --list \
            --license --no-name --name --quiet --recursive \
            --suffix --test --verbose --version --fast \
            --best' -- $cur ) )
        return 0
    fi

    xspec="*.?(t)gz"
    if [[ "$prev" == --* ]]; then
        [[ "$prev" == --decompress || \
            "$prev" == --list || \
            "$prev" == --test ]] && xspec="!"$xspec
        [[ "$prev" == --force ]] && xspec=
    elif [[ "$prev" == -* ]]; then
        [[ "$prev" == -*[dlt]* ]] && xspec="!"$xspec
        [[ "$prev" == -*f* ]] && xspec=
    elif [ "$prev" = '>' ]; then
        xspec=
    elif [ "$prev" = '<' ]; then
        xspec=
    fi

    _expand || return 0

    COMPREPLY=( $( compgen -f -X "$xspec" -- $cur ) \
            $( compgen -d -- $cur ) )
} # _gzip()
